<template>
    <div class="electricianUsers">
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位名称</label>
            </div>
            <div class="equipment-right-select"
                 @click="companyPropShow = true"
                 v-if="userInfo.departsir != '1'">
                <span>{{deptname}}</span>
                <i class="iconfont icon-jinru rightmsg"></i>
            </div>
            <div class="equipment-right-select"
                 v-else>
                <span>{{deptname}}</span>
            </div>
        </div>
        <h2>人员数量: {{sumCount}}人</h2>
        <noData v-if="listAllCount == 0"></noData>
        <div class="bscroll1">
            <vue-better-scroll class="wrapper"
                               ref="scroll"
                               :scrollbar="scrollbarObj"
                               :pullDownRefresh="pullDownRefreshObj"
                               :pullUpLoad="pullUpLoadObj"
                               :startY="parseInt(startY)"
                               @pullingDown="onPullingDown"
                               @pullingUp="onPullingUp">
                <div class="bscroll-container">
                    <div class="form-section"
                         v-for="(item,index) in list"
                         :key="index">
                        <div>
                            <div class="form-item  form-item-style1"
                                 @click="getUserList(item)">
                                <div class="label-title">
                                    <label>{{item.DepartName}}</label>
                                </div>
                                <div style="display:flex;align-items: center;">
                                    <p>{{item.DgSum}}人</p>
                                    <x-icon type="ios-arrow-down"
                                            fill="#999"
                                            size="24"
                                            v-if="item.DgSum>0"
                                            v-show="!item.open"></x-icon>
                                    <x-icon type="ios-arrow-up"
                                            fill="#999"
                                            size="24"
                                            v-if="item.DgSum>0"
                                            v-show="item.open"></x-icon>
                                </div>
                            </div>
                            <div class="form-section sectionML20"
                                 style="border-bottom:1px solid #f4f4f4;"
                                 v-if="item.DgSum>0"
                                 v-show="item.open">
                                <router-link :to="{path:'/electricianUsersDetail',query:{id:childItem.ID}}"
                                             class="form-item form-item-style1"
                                             v-for="(childItem,index) in item.children"
                                             :key="index">
                                    <div class="label-title label-title1">
                                        <label>{{childItem.PersonName}}</label>
                                    </div>
                                    <div class="right-section">
                                        <x-icon type="ios-arrow-right"
                                                size="20"
                                                class="icon-right"></x-icon>
                                    </div>
                                </router-link>
                            </div>
                        </div>
                    </div>
                </div>
            </vue-better-scroll>
        </div>
        <companyProp :companyPropShow="companyPropShow"
                     :selectCompany="selectCompany"></companyProp>
        <myMenu ref="myMenu"></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
import VueBetterScroll from 'vue2-better-scroll'
import companyProp from '@/commonComponents/companyProp'
export default {
    name: 'electricianUsers',
    components: {
        VueBetterScroll,
        myMenu,
        companyProp
    },
    data () {
        return {
            userInfo: {},
            // dropDown: false
            // 这个配置可以开启滚动条，默认为 false。当设置为 true 或者是一个 Object 的时候，都会开启滚动条，默认是会 fade 的
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: {
                threshold: 90,
                stop: 40
            },
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            scrollToX: 0,
            scrollToY: 0,
            scrollToTime: 700,
            companyPropShow: false,
            deptname: '',
            deptId: '',
            listAllCount: 0,
            listCount: 0,
            pageIndex: 0,
            list: [],
            sumCount: 0
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.deptname = this.userInfo.deptname
        this.deptId = this.userInfo.deptid
        this.onPullingDown()
    },
    activated () {
        if (this.$refs.myMenu) this.$refs.myMenu.flag = false
    },
    methods: {
        itemOpen (item) {
            this.$set(item, 'open', !item.open)
        },
        onPullingDown () {
            // 模拟下拉刷新
            this.listCount = 0
            this.pageIndex = 0
            this.list = []
            this.getData()
        },
        onPullingUp () {
            this.pageIndex++
            this.getData()
        },
        getData () { // 获取通知公告
            var params = {
                'business': 'GetElectricianRosterData',
                'data': {
                    'DepartId': this.deptId
                },
                'pageIndex': this.pageIndex,
                'pageSize': 10,
                'userId': this.userInfo.userid
            }

            this.$axiosAjax.getConfigJson(params)
                .then((res) => {
                    if (res.data.code === 0) {
                        this.list = this.list.concat(res.data.data.result)
                        this.listAllCount = res.data.count
                        this.listCount = this.list.length
                        this.sumCount = res.data.data.sumCount
                    }
                    if (this.listCount < this.listAllCount) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }).catch((response) => {
                })
        },
        getUserList (item) {
            if (item.DgSum <= 0) return false
            if (item.children) {
                this.$set(item, 'open', !item.open)
                return false
            }
            var params = {
                'business': 'GetElectricianRosterData_JJ',
                'data': {
                    'id': item.ID
                },
                'pageIndex': 0,
                'pageSize': 100000,
                'userId': this.userInfo.userid
            }

            this.$axiosAjax.getConfigJson(params)
                .then((res) => {
                    if (res.data.code === 0) {
                        this.$set(item, 'children', res.data.data)
                        this.$set(item, 'open', true)
                    }
                }).catch((response) => {
                })
        },
        selectCompany (item) {
            this.companyPropShow = false
            this.deptname = item.Name
            this.deptId = item.Id
            this.onPullingDown()
        }
    }
}
</script>
<style scoped>
.paddingR12 {
    padding-right: 12px;
}
.header {
    height: 62px;
    display: flex;
    width: 100%;
    justify-content: space-around;
    padding-top: 5px;
    background-color: #fff;
}
.electricianUsers h2 {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: right;
    padding-right: 20px;
    box-sizing: border-box;
    background: #ebeef2;
}
.itemlist {
    width: 75px;
    height: 100%;
    line-height: 62px;
    text-align: center;
    position: relative;
}
.itemlist.active {
    color: #2269ff;
}
.itemlist.active::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #2269ff;
    height: 5px;
}
.division-line {
    height: 4px;
    background: #ebeef2;
}
.electricianUsers .bscroll1 {
    position: absolute;
    top: 95px;
    bottom: 0;
    left: 0;
    right: 0;
    overflow: hidden;
}
.bscroll-container li {
    border-bottom: 1px solid #efeff4;
    padding: 18px 20px 12px 0;
}
.bscroll-container li > a {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.bscroll-container li h3 {
    font-size: 14px;
    color: #333;
    line-height: 20px;
    padding-bottom: 10px;
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bscroll-container li p {
    font-size: 14px;
    color: #999;
}
.sectionML20 {
    margin-left: 20px;
}
.bscroll-container .form-item label {
    width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
</style>
